package com.chagee.store.operation.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author : hk
 * @Date : 2024/9/26
 */
@Configuration
public class ThreadPoolConfig {

	@Bean("workOrderAISyncExecutor")
	public ThreadPoolTaskExecutor workOrderAISyncExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		//配置核心线程数
		executor.setCorePoolSize(5);
		//配置最大线程数
		executor.setMaxPoolSize(20);
		//配置队列大小(1000ms/200ms*18=90)
		executor.setQueueCapacity(20);
		//配置线程池中的线程的名称前缀
		executor.setThreadNamePrefix("WorkOrderAISyncExecutor-");
		// 放置主线程执行
		executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		//执行初始化
		executor.initialize();
		return executor;
	}

}
